package taiyuaneltyl.com.my_mvp.presenter;

import android.os.Handler;

import com.google.gson.Gson;

import taiyuaneltyl.com.my_mvp.Bean.LoginBean;
import taiyuaneltyl.com.my_mvp.View.LoginView;
import taiyuaneltyl.com.my_mvp.model.LoginNet;
import taiyuaneltyl.com.my_mvp.model.LoginNetIml;

/**
 *    M层和V交互
 */

public class OnLoginListenerImpl {
    private LoginNet baseNet;
    private LoginView loginView;

    public OnLoginListenerImpl(LoginView loginView) {
        this.loginView = loginView;
        baseNet = new LoginNetIml();
    }

    /**
     * login在登陆的监听调用
     *
     *
     */
    public void login() {

        loginView.Onloading();
        baseNet.Login(loginView.getUserName(), loginView.getPassword(), loginView.getRid(), new LoginOnListener() {
            @Override
            public void onpSuccess(String mbean) {
                LoginBean loginBean = new Gson().fromJson(mbean, LoginBean.class);
               if (loginBean.getCode()==1) {
                   loginView.OnSuccess(mbean);
                   loginView.Ondismiss();
               } else {
                   loginView.Onfail("");
                   loginView.Ondismiss();
               }
            }

            @Override
            public void onError() {
                loginView.Onfail("");
                loginView.Ondismiss();
            }
        });


    }


/**
  private String username = "17635392661";
 private String pwod = "123456";
 private String rrid = "132321";
 XRecyclerView xRecyclerView;
 private int page = 1;
 xRecyclerView = findViewById(R.id.RecyclerView);
 xRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
@Override
public void onRefresh() {
page = 1;

}

@Override
public void onLoadMore() {
page++;

}
});
 */
}
